package com.grandbroad.eim.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.easy.west.westclient.api.vod.bean.CollectList;
import com.grandbroad.eim.R;
import com.grandbroad.eim.utils.TimeUtils;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ColloectVodAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<CollectList.DataBean> dataBeanList = new ArrayList<>();

    public void setDataBeanList(List<CollectList.DataBean> dataBeanList) {
        this.dataBeanList = dataBeanList;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.class_item, viewGroup, false);
        return new CollectVodViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if (viewHolder instanceof CollectVodViewHolder)
        {
            CollectVodViewHolder vodViewHolder = (CollectVodViewHolder) viewHolder;
            CollectList.DataBean dataBean = dataBeanList.get(i);
            vodViewHolder.tvSeeCount.setText(dataBean.getVod().getCount()+"");
            vodViewHolder.tvVodName.setText(dataBean.getVod().getName());
            vodViewHolder.tvVodTime.setText(TimeUtils.formatGTtime(dataBean.getVod().getCreated_at()));
            vodViewHolder.tvVodUsername.setText(dataBean.getVod().getUser().getName());
            x.image().bind(vodViewHolder.imgClassItem,dataBean.getVod().getCover_img());
            //点击事件需要转化实体


        }
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    /**
     * 收藏列表界面
     */
    class CollectVodViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_class_item)
        ImageView imgClassItem;
        @BindView(R.id.tv_see_count)
        TextView tvSeeCount;
        @BindView(R.id.tv_vod_name)
        TextView tvVodName;
        @BindView(R.id.tv_vod_username)
        TextView tvVodUsername;
        @BindView(R.id.tv_vod_time)
        TextView tvVodTime;
        public CollectVodViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
